package cn.shyouchi.wuguanjia.android.ui.patrol.statistic;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.Global;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.impl.ModuleItemClickListener;
import cn.shyouchi.wuguanjia.android.ui.patrol.statistic.page.PreviewPatrolInfoActivity;
import cn.shyouchi.wuguanjia.android.widget.GlideCircleTransform;
import cn.shyouchi.wuguanjia.android.widget.TopBar;

public class PreviewPatrolRingActivity extends BaseActivity  implements ModuleItemClickListener<PatrolStatisticEntity.ResultMessageBean.InfoBean> {

    @Override
    public int initContentView() {
        return R.layout.activity_preview_patrol_ring;
    }

    @BindView(R.id.topBar)
    TopBar mTopBar;
    @BindView(R.id.img_header)
    ImageView mImgHeader;
    @BindView(R.id.tv_person_name)
    TextView mTvPersonName;
    @BindView(R.id.rv_ring_des)
    RecyclerView mRvRingDes;
    PreviewPatrolRingDesAdapter mPatrolRingDesAdapter;
    List<PatrolStatisticEntity.ResultMessageBean.InfoBean> mPatrolRingDesEntities = new ArrayList<>();
    PatrolStatisticEntity.ResultMessageBean entity;



    @Override
    public void initInjector() {
        entity = getIntent().getParcelableExtra("info");
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());

        mPatrolRingDesEntities.addAll(entity.getInfo());
        mPatrolRingDesAdapter = new PreviewPatrolRingDesAdapter(mPatrolRingDesEntities, this);
        mRvRingDes.setLayoutManager(new LinearLayoutManager(mContext));
        mRvRingDes.setAdapter(mPatrolRingDesAdapter);

        bindPersonDetail();
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }


    private void bindPersonDetail() {
        mTvPersonName.setText(entity.getUser().getName());
        loadHead(Global.BASE_URL + entity.getUser().getId_card_head_image());
    }

    private void loadHead(String path) {
        Glide.with(mContext)
                .load(path)
                .placeholder(R.mipmap.ic_default_header)
                .transform(new GlideCircleTransform(mContext))
                .into(mImgHeader);
    }


    @Override
    public void moduleItemClick(PatrolStatisticEntity.ResultMessageBean.InfoBean model) {
        Intent intent = new Intent(mContext, PreviewPatrolInfoActivity.class);
        intent.putExtra("info", model);
        startActivity(intent);
    }

    @Override
    public void moduleItemLongClick(PatrolStatisticEntity.ResultMessageBean.InfoBean model) {

    }

    @Override
    public void onDel(PatrolStatisticEntity.ResultMessageBean.InfoBean model) {

    }
}
